package com.bum.api.processor.dev.html;

import org.apache.commons.lang.StringUtils;

import com.bum.api.core.exp.om.Metas;
import com.bum.api.core.exp.om.Params;
import com.bum.api.core.service.process.ApiProcess;
import com.bum.api.processor.dev.html.bo.DevHtmlBO;

public class DevHtmlProcess extends ApiProcess {
	enum Func {
		base64,
		url,
		myip,
		agent;
		public static Func val(String val) {
			try {
				return valueOf(val);
			} catch (Exception e) {
				return null;
			}
		}
	}

	DevHtmlBO	devHtmlBO;

	@Override
	public String process(String path, Params params, Metas metas) {
		String[] parts = StringUtils.split(path, "/", 3);
		if (parts.length > 1) {
			Func func = Func.val(parts[1]);
			if (func != null) {
				switch (func) {
					case base64:
						return devHtmlBO.base64(null, params, metas);
					case url:
						return devHtmlBO.url(null, params, metas);
						
					case myip:
						return devHtmlBO.myip(null, params, metas);
						
					case agent:
						return devHtmlBO.userAgentInfo(null, params, metas);
				}
			}
		}

		return super.process(path, params, metas);
	}

	/**
	 * SETTERS
	 */
	public void setDevHtmlBO(DevHtmlBO devHtmlBO) {
		this.devHtmlBO = devHtmlBO;
	}
}